package cn.bj.ykct.spring.boot.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.bj.ykct.spring.data.test.TableOne;
import cn.bj.ykct.spring.repository.test.TableOneRepository;

@Controller
public class TableOneController {

	private static final String template = "Hello, %s!";

	@Autowired
	TableOneRepository tableOneRepo;

	@RequestMapping(value = "/toTableOne", method = RequestMethod.GET)
	public String toTableOne() {
		
		return "tableOne";
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String addTableOne(Model model, @RequestParam(name = "name") String name) {
		TableOne bean = new TableOne();
		bean.setName(name);
		tableOneRepo.save(bean);
		model.addAttribute("addResult", String.format(template, name));
		return "tableOne";
	}
}
